-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tooling] Switch from flake8
to ruff
#15362
Conversation
To quote Ruff's README: "An extremely fast Python linter, written in Rust". In my testing Ruff takes 200ms to lint the entire codebase whereas flake8 takes about 5.5 seconds (27x slower). Running `pre-commit run -a` only takes about 2.3 seconds now, which should make local dev work a bit faster (assuming you run linters regularly). Ruff includes a lot of rules out of the box, including all the (important) rules from `flake8`, `flake8-bugbear`, `flake8-noqa`, and many more. Having all these built-in rules makes it much easier to incrementally improve the codebase without having to install tons of flake8 plugins. I made sure that the configs matched as close as I could get them. Some minor rules like line indentation and such aren't in Ruff since they are always just disabled. Ruff also ignores everything in the `.gitignore` file, so that cleans up the exclude section. Lastly, the `test-data` section seemed to have its own `.flake8` config file, but it was disabled in the `setup.cfg` file. I migrated the config over, but it doesn't really matter because it is being ignored anyways. Is this intentional?
This comment has been minimized.
This comment has been minimized.
I experimented with this a bit. It makes linting much faster. It seems particularly nice now that we've migrated to Black, as linting is somewhat less important than it used to be -- many style issues can be auto-fixed. Waiting for a lint run that usually only finds some missing imports seems wasteful to me. Does anybody else have thoughts about this? I'm positive about this, but I'd like to hear if somebody else has opinions. |
I'm +1 on this. Ruff is incredibly fast, and the autofixes are pretty nice. The tool is newer than flake8, but it's also very actively developed, so I'm confident any bugs in ruff would be fixed pretty quickly if we stumbled upon them. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I posted some comments about config. I like the autofixes.
I started using ruff at work this week for autofix reasons. I ran into like five bugs, but two were already fixed when I went to report, a third was fixed very fast, a fourth was upstream in the rust parser, and none would affect mypy's usage here. Overall, works well and I'm in favour!
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <[email protected]>
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
To quote Ruff's README: "An extremely fast Python linter, written in Rust".
In my testing Ruff takes 200ms to lint the entire codebase whereas flake8 takes about 5.5 seconds (27x slower). Running
pre-commit run -a
only takes about 2.3 seconds now, which should make local dev work a bit faster (assuming you run linters regularly).Ruff includes a lot of rules out of the box, including all the (important) rules from
flake8
,flake8-bugbear
,flake8-noqa
, and many more. Having all these built-in rules makes it much easier to incrementally enable checks/flags without having to install tons of flake8 plugins. You can see a full list of common flake8 plugins Ruff supports here.I made sure that the configs matched as close as I could get them. Some minor rules like line indentation and such aren't in Ruff since they are always just disabled. Ruff also ignores everything in the
.gitignore
file, so that cleans up the exclude section.Lastly, the
test-data
folder seemed to have its own.flake8
config file, but it was disabled in thesetup.cfg
file. I migrated the config over, but it doesn't really matter because it is being ignored anyways. Is this intentional?